<template>
  <view class="success-mask" v-if="show" @click="handleMaskClick">
    <view class="success-content" @click.stop>
      <!-- 成功图标 -->
      <image class="success-icon" src="/static/org/org-success.png" mode="aspectFit"></image>
      <!-- 成功文本 -->
      <text class="success-text">注册成功</text>
    </view>
  </view>
</template>

<script setup>
import { ref, onBeforeUnmount } from 'vue'

const show = ref(false)
const emit = defineEmits(['close'])
let timer = null

// 打开弹窗
const open = () => {
  show.value = true
  // 3秒后自动关闭
  timer = setTimeout(() => {
    close()
  }, 3000)
}

// 关闭弹窗
const close = () => {
  show.value = false
  clearTimeout(timer)
  emit('close')
}

// 处理蒙版点击
const handleMaskClick = () => {
  close()
}

// 组件卸载时清除定时器
onBeforeUnmount(() => {
  clearTimeout(timer)
})

defineExpose({
  open,
  close
})
</script>

<style scoped>
.success-mask {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.success-content {
  background: #FFFFFF;
  border-radius: 20rpx;
  width: 400rpx;
  padding: 60rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.success-icon {
  width: 120rpx;
  height: 120rpx;
  margin-bottom: 40rpx;
}

.success-text {
  font-size: 36rpx;
  color: #000000;
  font-weight: 500;
}
</style> 